﻿@using viBook.Models
@model IEnumerable<ReportOnUser>
@{
    ViewBag.Title = "User Report";
    ViewBag.Menu = "Report";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
@(Html.Telerik().Grid(Model)
               .Name("report-user")
               .DataKeys(keys => keys.Add(c => c.Id))
               .Columns(columns =>
                            {
                                columns.Bound(c => c.Id).Width(50);
                                columns.Bound(c => c.ReportedDate).Format("{0:dd/MM/yyyy H:mm:ss}").Width(150);
                                columns.Bound(c => c.ReporteeId)
                                    .Template(
                                        @<text>
                                            <a href='@Url.Action("Index","Account", new {id = item.ReporteeId})'>@item.Reportee.DisplayName</a>
                                        </text>)
                                    .ClientTemplate(
                                        string.Format("<a href='/Account/Index/<#= ReporteeId #>'><#= Reportee.DisplayName #></a>")
                                    )
                                    .Title("Reportee")
                                    .Width(200);
                                columns.Bound(c => c.Id)
                                    .Template(
                                        @<text> 
                                            <a href='javascript:approve(@item.Id)' class='t-button'>Approve</a>
                                            <a href='javascript:disapprove(@item.Id)' class='t-button'>Disapprove</a>
                                        </text>
                                    )
                                    .ClientTemplate(
                                        string.Format("<a class='t-button' href='javascript:approve(<#= Id #>)'>Approve</a>" +
                                                      "<a class='t-button' href='javascript:disapprove(<#= Id #>)'>Disapprove</a>")
                                    )
                                    .Title("Action")
                                    .Width(140);
                            })
                .DataBinding(dataBinding =>
                {
                    dataBinding.Server().Select("UsersReport", "Admins");
                    dataBinding.Ajax().Select("SelectUserReportAjax", "Admins").Enabled(true);
                })
                .Scrollable()
                .Sortable()
                .Pageable() 
                .Filterable()
                .Footer(true)
        )
<script type="text/javascript">
    function approve(id) {
        $.ajax({
            url: '@Url.Action("ApproveUserReportAjax", "Admins")',
            type: 'POST',
            data: "{ id:" + id + "}",
            contentType: 'APPLICATION/JSON',
            success: function (result) {
                var reportUserGrid = $('#report-user').data('tGrid');
                reportUserGrid.rebind();
            }
        });
    }
    
    function disapprove(id) {
        $.ajax({
            url: '@Url.Action("DisapproveUserReportAjax", "Admins")',
            type: 'POST',
            data: "{ id:" + id + "}",
            contentType: 'APPLICATION/JSON',
            success: function (result) {
                var reportUserGrid = $('#report-user').data('tGrid');
                reportUserGrid.rebind();
            }
        });
    }
</script>